Repository navigation
feat(db): add release_level alongside release_status (BDMS-1382) - #1052
Conversation
Coverage❌ 43.17% total — gate is 75%. Coverage for the Python files changed in this PR
|
e0ce2bf to
ed4e2f4
Compare
Coverage✅ 82.03% total — gate is 75%. Coverage for the Python files changed in this PR
|
| for table in TABLES: | ||
| op.add_column( | ||
| table, | ||
| sa.Column("release_level", sa.String(length=100), nullable=True), |
There was a problem hiding this comment.
I don't think that this should be nullable. The lexicon_term column in the mixin is a foreign key, which can't be nullable (I think?)
There was a problem hiding this comment.
Made it NOT NULL — agreed it shouldn't ever be empty. One small correction though: I think FKs actually can be nullable (release_status already is, same pattern), just added it as nullable first, backfilled every row, then locked it to NOT NULL once every row had a real value.
| 5. **Assuming, not yet confirmed: the `TransducerObservation` (76,725 | ||
| rows) and `TransducerObservationBlock` (108 rows) rows with | ||
| `release_status='provisional'` become `release_level='pending'`,** | ||
| migrated in the same pass as every other table rather than held back | ||
| separately. Based on the evidence so far (every one of these rows also | ||
| has `data_maturity='provisional'`, never `approved`; `docs/ | ||
| hydrograph-correction-publish.md` describes "publishing as provisional" | ||
| as a deliberate operator choice distinct from `public`) — needs real | ||
| sign-off from the team. |
There was a problem hiding this comment.
I think that release_status='provisional' has to do with review_state, not release_level. I'd assume that the transducer data should have a 'public' release_level, though I'd check with others on that.
There was a problem hiding this comment.
These rows currently have both release_status='provisional' and data_maturity='provisional'. If review_state becomes provisional for them, that matches the existing data_maturity value. For release_level (the visibility axis), we proposed pending based on the our discussion, but happy to change it to public if the team agrees that's the better call.
|
@likithabommasani21, regarding the BDD scenario failures: "These scenarios deliberately rewind the real database schema to an old revision (PRE_A1_REVISION, well before this change) to test an old migration in isolation." Maybe it's best to review the scenarios and make sure they are still relevant/valuable. |
The two failing scenarios only test the old migration's isolated replay — seems low-value now, and it'll keep breaking on future shared-mixin changes. Agreed it's worth reviewing, I will bring it up as a separate ticket |
8ad9457 to
2d9524f
Compare
ksmuczynski
left a comment
There was a problem hiding this comment.
Looking good! Just two comments for consideration.
| f"{dict(unaccounted)}" | ||
| ) | ||
|
|
||
| op.alter_column(table, "release_level", nullable=False) |
There was a problem hiding this comment.
I think we should set pending as the database-level default for release_level.
Currently, only SQLAlchemy sets this default, so any raw SQL INSERT that omits release_level will violate the NOT NULL constraint. This is why tests/features/environment.py required updates in this PR, and our manual SQL scripts will run into the same failure.
To fix this, update the migration line to:
op.alter_column(
table, "release_level", nullable=False, server_default="pending"
)I'd also add server_default="pending" to release_level in ReleaseMixin.
The default should go in alter_column after the backfill. If we set it in add_column, all existing rows become pending immediately, and the migration won't catch any unmapped release_status values.
| for release_status, release_level in ( | ||
| ("public", "public"), | ||
| ("private", "private"), | ||
| ("draft", "pending"), | ||
| ("provisional", "pending"), | ||
| ): | ||
| connection.execute( | ||
| sa.text( | ||
| f'UPDATE "{table}" SET release_level = :release_level ' | ||
| f"WHERE release_status = :release_status" | ||
| ), | ||
| {"release_status": release_status, "release_level": release_level}, | ||
| ) |
There was a problem hiding this comment.
I think we need a follow-up ticket (linked here before merging) to re-run this backfill when the readers switch over to release_level.
Right now, every write path only updates release_status, so release_level won’t stay in sync for any rows created or modified after this migration runs:
- Well inventory importer: creates public wells with
release_level = 'pending'. - Water level importer and hydrograph publish: create observations with
release_level = 'pending', regardless of therelease_statusthey set. - PATCH routes: update
release_statuswithout touchingrelease_level, so a record changed from public to private keepsrelease_level = 'public'.
Since nothing reads release_level yet, merging this won’t break anything. However, once views and filters switch to release_level, records created or made public after this migration will be missing from public views, while records made private after it will still appear in them.
To keep them aligned, the migration that switches the readers over should also re-run this backfill so release_level matches release_status when the switch happens.
There was a problem hiding this comment.
Agreed this is safe to merge as-is since nothing reads release_level yet, but opening a follow-up ticket to re-run the backfill when readers switch over
jacob-a-brown
left a comment
There was a problem hiding this comment.
Are there views (materialized or otherwise) that depend on release_status? If so should those get alembic-migrated here, too?
Updating those views/queries to actually use release_level is tracked separately in [1595], along with a re-backfill step before that cutover. |
…al rename 73d27e78571a and 7480e4ee69dc (BDMS-1554, already merged to staging) both branched off the same parent, creating two alembic heads. Chains this migration after 7480e4ee69dc instead, and swaps thing_geologic_formation_association for its new name, stratigraphic_interval, since that table no longer exists under the old one by the time this migration runs. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
f612e47 to
da3781d
Compare
Coverage✅ 82.03% total — gate is 75%. Coverage for the Python files changed in this PR
|
|
Your pull request is automatically being deployed to Dagster Cloud.
|
Why
This PR addresses the following problem / context:
ReleaseMixingives every record onerelease_statuscolumn that's being asked two unrelated questions at once: who may see it, and how far along it is in review. Perdocs/release-level-and-data-maturity-vocabulary.md, this is step one of splitting that into two independent fields: addingrelease_levelalongside the existing column.How
Implementation summary: the following was changed / added / removed:
release_levellexicon category (pending/private/public) tocore/lexicon.json, tagging the existingpublic/privateterms and adding the newpendingterm. AddedReleaseLeveltocore/enums.py.release_leveltodb/base.py'sReleaseMixin, defaulting new rows topending.73d27e78571a: addsrelease_levelto all 35ReleaseMixintables and backfills it by exact value name only (public→public,private→private,draft/provisional→pending) -- raises rather than guessing if any other value shows up, sincepublished/final/archivedare expected to have zero rows anywhere.release_levelto the_versionshadow table of the 7__versioned__(sqlalchemy_continuum) tables among those 35, which must mirror the live table's columns or every write to them fails.release_statusis not dropped in this PR -- kept for now, consumers migrated and the column dropped in later follow-ups.Author Checklist
Reviewer Checklist
draft/provisional→pendingis the right backfill, and that raising on any other value (rather than defaulting it) is the right call.provisional→pendingfortransducer_observation/transducer_observation_blockspecifically -- this is still an assumption pending sign-off from whoever owns the hydrograph correction workflow, not a final decision.release_statusin place for now (two-step rollout) rather than dropping it in this same PR.Notes
Any special considerations, known limitations, risks, workarounds, or follow-up work to note?
This PR only adds
release_leveland backfills it -- updating the ~38 consumer files, the two materialized chemistry views, and droppingrelease_statusare separate follow-up steps, not part of this PR.Verified: migration applies and reverts cleanly on a fresh local database; full test suite passes (1299 passed, 0 failures, excluding modules with a pre-existing unrelated missing-dependency issue in this environment).
Two BDD scenarios in
tests/features/ogc-cleanup-sprint1.featurefail against this branch: "Sprint 1 migration restricts all ogc_* views to public records" and "The 4 already-consistent layers are unaffected by the migration."Root cause: these scenarios deliberately rewind the real database schema to an old revision (
PRE_A1_REVISION, well before this change) to test an old migration in isolation, then seed test data using the current SQLAlchemy ORM model classes. Sincerelease_levelis now a mapped column onReleaseMixin, every model using it (Group,Location, etc.) always includesrelease_levelin its generatedINSERTstatement -- regardless of whether it's set, and regardless of any default (client-side, server-side, or none at all; all three were tried and all fail the same way). Against the rewound schema, that column doesn't exist yet, so the insert fails withcolumn "release_level" of relation "group" does not exist.I think this needs a fix on the test side (e.g.,
_seed_allintests/features/steps/ogc-cleanup-sprint1.pyseeding via raw SQL instead of the ORM for these two scenarios specifically) -- not resolved in this PR. @ksmuczynski @jirhiker any thoughts on this ?